#include <iostream>
#include <algorithm>
#define MAXN 45
#define INF LONG_LONG_MAX
using namespace std;
typedef long long ll;
int N;
ll w[MAXN], v[MAXN];
ll W;
pair<ll, ll> ps[1 << (MAXN / 2)];

int main() {
    cin >> N;
    for (int i = 0; i < N; i++)
        cin >> w[i];
    for (int i = 0; i < N; i++)
        cin >> v[i];
    cin >> W;
    solve();
}

void solve() {
    int n2 = N / 2;
    for (int i = 0; i < 1 << n2; i++) {
        ll sw = 0, sv = 0;
        for (int j = 0; j < n2; j++) {
            if (i >> j & 1) {
                sw += w[j];
                sv += v[j];
            }
        }
        ps[i] = make_pair(sw, sv);
    }

    sort(ps, ps + (1 << n2));
    int m = 1;
    for (int i = 1; i < 1 << n2; i++) {
        if (ps[m - 1].second < ps[i].second) {
            ps[m++] = ps[i];
        }
    }

    ll res = 0;
    for (int i = 0; i < 1 << (N - n2); i++) {
        ll sw = 0, sv = 0;
        for (int j = 0; j < N - n2; j++) {
            if (i >> j & 1) {
                sw += w[n2 + j];
                sv += v[n2 + j];
            }
        }
        if (sw <= W) {
            ll tv = (lower_bound(ps, ps + m, make_pair(W - sw, INF)) - 1)->second;
            res = max(res, sv + tv);
        }
    }
    cout << res << endl;
}